#include "CTaskTreeItem.h"

CTaskTreeItem::CTaskTreeItem(QTreeWidget *parent, STask *task)
	: QTreeWidgetItem(QTreeWidgetItem::UserType), m_task(task)
{
	updateData();
}

void CTaskTreeItem::setTask(STask *task)
{
	m_task = task;
	updateData();
}

STask* CTaskTreeItem::task()
{
	return m_task;
}

void CTaskTreeItem::updateData()
{
	if(m_task != 0)
	{
		setText(0, m_task->name);
		
		// Adds task details
		addInformations(tr("Description"), m_task->description);
		addInformations(tr("Added date"), m_task->addDate.toString());
		addInformations(tr("Due date"), m_task->dueDate.toString());
		addInformations(tr("Priority"), QString::number(m_task->priority));
	}
}

void CTaskTreeItem::addInformations(QString label, QString info)
{
	if(!info.isEmpty())
	{
		QTreeWidgetItem *itm = new QTreeWidgetItem(this);
		
		if(label.isEmpty())
			itm->setText(0, info);
		else
			itm->setText(0, label + ": " + info);
	}
}
